package com.sh.rpc.registry;

import com.sh.rpc.model.ServiceMetaInfo;

import java.util.List;

/**
 * 本地缓存，不用每次都向注册中心查询
 * @author sh
 */
public class RegistryServiceCache {


    /**
     * 缓存服务列表
     */
    List<ServiceMetaInfo> serviceCache;


    /**
     * 写
     */
    void writeCache(List<ServiceMetaInfo> newServiceCache) {
        this.serviceCache = newServiceCache;
    }

    /**
     * 读
     */
    List<ServiceMetaInfo> readCache() {
        return this.serviceCache;
    }

    /**
     * 清除缓存
     */
    void clearCache(String serviceNodeKey) {
        this.serviceCache.removeIf(item -> item.getServiceNodeKey().equals(serviceNodeKey));
    }

}
